<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtiframe.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Driving_History extends Page
{
       public $btnAddG = null;
       public $Label14 = null;
       public $Image3 = null;
       public $btnAdd = null;
       public $hfincident = null;
       public $hfVeh = null;
       public $edDesc = null;
       public $Label8 = null;
       public $Label9 = null;
       public $edAmt = null;
       public $JTIFrameCost = null;
       public $memoDesc = null;
       public $cmbdriver = null;
       public $Label6 = null;
       public $Label5 = null;
       public $edIncidentNum = null;
       public $btnShowType = null;
       public $dpDate = null;
       public $lblMobile = null;
       public $cmbType = null;
       public $lblJob = null;
       public $lblBirthdate = null;
       public $JTGroupBox2 = null;
       public $JTDivType = null;
       public $JTGroupBox1 = null;
       public $btnAddType = null;
       public $btnDelType = null;
       public $edType = null;
       public $listType = null;
       public $chkpersonalinjury = null;
       public $chkatfault = null;
       public $imgBack = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $compid = null;
       public $JTSiteTheme1 = null;
       public $hiddenDrivingHistory = null;
       public $hiddenEmpId = null;
       public $Image1 = null;
       function btnAddGJSClick($sender, $params)
       {

       ?>
       var veh = document.getElementById("hfVeh").value;
       var inc = document.getElementById("hfincident").value;
       var win_height = 120;
       var win_width = 304;
       var height = window.outerHeight;
       var width = window.outerWidth;
       var top = Math.round((height-win_height)/2);
       var left = Math.round((width-win_width)/2);
       window.open("cost_add.php?veh="+veh+"&inc="+inc,'cost_add','location=no,height='+win_height+',width='+win_width+',top='+top+',left='+left);

       <?php

       }

       function btnAddClick($sender, $params)
       {
       $result_cost = mysql_query("insert into incident_cost_tbl (company_id,
       vehicle_id,
       incident_id,
       description,
       amount)

       values ('".$_SESSION['company_id']."',
       '".$this->hfVeh->getValue()."',
       '".$this->hfincident->getValue()."',
       '".$this->edDesc->Text."',
       '".$this->edAmt->Text."')");

       echo "<script language=javascript>
       document.getElementById('JTIFrameCost').location.reload();
       </script>";

       return false;


       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }


       function btnDelTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var TypeIndex = document.getElementById('listType').selectedIndex;
       var TypeValue = document.getElementById('listType')[TypeIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxType3(TypeValue,comp);
       <?php

       }


       function btnAddTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addtype = document.getElementById('edType').value;
       var comp = document.getElementById('compid').value;
       AjaxType2(addtype,comp);
       document.Driving_History.edType.value = "";
       <?php

       }

       function btnShowTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivType').Show();
       document.Driving_History.edType.value = "";
       <?php

       }
       function btnSubmitClick($sender, $params)
       {

       mysql_query("update veh_incident_tbl set
       date ='".$this->dpDate->Text."',
       type ='".$this->cmbType->getItemIndex()."',
       description = '".$this->memoDesc->Text."',
       driver = '".$this->cmbdriver->getItemIndex()."'
       where vehicle_id='".$this->hfVeh->getValue()."'and incident_id ='".$this->hfincident->getValue()."'")or die("UPDATE INCIDENT - " . mysql_error());

       $query_up_inc = "UPDATE incident_cost_tbl SET
       date='".$this->dpDate->Text."',
       type='".$this->cmbType->getItemIndex()."',
       desc_main='".$this->memoDesc->Text."' WHERE incident_id='".$this->hfincident->getValue()."'";
       mysql_query($query_up_inc) or die("UPDATE INC ".mysql_error());

       redirect('veh_incident_list.php?veh='.$this->hfVeh->getValue());


       }

       function btnCancelClick($sender, $params)
       {
       redirect('veh_incident_list.php?veh='.$this->hfVeh->getValue());


       }

       function Driving_HistoryCreate($sender, $params)
       {
       $this->compid->Value = $_SESSION['company_id'];
       $veh = $_GET['veh'];
       $incident = $_GET['journal'];
       //$driving_history = $_GET['driving_history'];
       $this->hfVeh->setValue($veh);
       if($incident!=null && $incident!='')
       $this->hfincident->setValue($incident);
       //$this->hiddenDrivingHistory->setValue($driving_history);

       if($_SESSION['access_vehicle']==1)
       {
       $this->btnCancel->Visible=false;
       $this->btnSubmit->Visible=false;
       $this->btnAddG->Visible=false;
       }

       if($_SESSION['access_vehicle']==2)
       {
       $this->btnCancel->Visible=true;
       $this->btnSubmit->Visible=true;
       $this->btnAddG->Visible=true;
       }


       $this->JTIFrameCost->setURL('incident_cost_list.php?incident='.$this->hfincident->getValue());
       $this->imgBack->setLink('veh_incident_list.php?layer=1&veh='.$this->hfVeh->getValue());

       $result_incident = mysql_query("select * from veh_incident_tbl where vehicle_id='".$this->hfVeh->getValue()."' and incident_id='".$this->hfincident->getValue()."'");
       $row_incident = mysql_fetch_array($result_incident);

       $this->cmbdriver->Clear();
       $this->cmbdriver->ItemIndex = $row_incident['driver'];
       $this->cmbdriver->AddItem('--Select--', null, null);
       $result_driver = mysql_query("select * from employee_tbl where company_id='".$_SESSION['company_id']."' and veh_op='1'");

       while($row_driver = mysql_fetch_array($result_driver))
        {
            $this->cmbdriver->AddItem($row_driver['lname'].','.$row_driver['fname'], null, $row_driver['lname'].','.$row_driver['fname']);
        }


       $this->cmbType->Clear();
       $this->cmbType->AddItem('--Select--', null, null);
       $this->cmbType->ItemIndex=$row_incident['type'];
       $result_type = mysql_query("select value from lookup_personnel_tbl where company_id= '".$_SESSION['company_id']."' AND category='driving history types'");

        while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
        }

        //list type
       $result_t = mysql_query("select value from lookup_personnel_tbl where company_id='".$_SESSION['company_id']."' AND category='driving history types'");

        while($row_t = mysql_fetch_array($result_t))
        {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
        }


       $this->dpDate->Text = $row_incident['date'];
       $this->edIncidentNum->Text = $row_incident['incident_num'];
       $this->memoDesc->Text = $row_incident['description'];


       }

}

global $application;

global $Driving_History;

//Creates the form
$Driving_History=new Driving_History($application);

//Read from resource file
$Driving_History->loadResource(__FILE__);

//Shows the form
$Driving_History->show();

?>